package com.logos.ruralrevitalization.service.impl;

import com.logos.ruralrevitalization.entity.OrderCartMapping;
import com.logos.ruralrevitalization.mapper.OrderCartMappingMapper;
import com.logos.ruralrevitalization.service.OrderCartMappingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单购物车关系表(OrderCartMapping)表服务实现类
 *
 * @author rose
 * @since 2025-03-29 13:24:36
 */
@Service("orderCartMappingService")
public class OrderCartMappingServiceImpl implements OrderCartMappingService {
    @Resource
    private OrderCartMappingMapper orderCartMappingMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrderCartMapping queryById(Long id) {
        return this.orderCartMappingMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderCartMapping 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderCartMapping> queryByPage(OrderCartMapping orderCartMapping, PageRequest pageRequest) {
        long total = this.orderCartMappingMapper.count(orderCartMapping);
        return new PageImpl<>(this.orderCartMappingMapper.queryAllByLimit(orderCartMapping, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderCartMapping 实例对象
     * @return 实例对象
     */
    @Override
    public OrderCartMapping insert(OrderCartMapping orderCartMapping) {
        this.orderCartMappingMapper.insert(orderCartMapping);
        return orderCartMapping;
    }

    /**
     * 修改数据
     *
     * @param orderCartMapping 实例对象
     * @return 实例对象
     */
    @Override
    public OrderCartMapping update(OrderCartMapping orderCartMapping) {
        this.orderCartMappingMapper.update(orderCartMapping);
        return this.queryById(orderCartMapping.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.orderCartMappingMapper.deleteById(id) > 0;
    }
}
